<template>
  <div class="app-container">
    <h4 class="form-header h4">编辑岗位</h4>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" style="padding-left:24px;">
      <el-form-item label="岗位名称" prop="postName">
        <el-input v-model="form.postName" placeholder="请输入岗位名称" style="width:240px" />
      </el-form-item>
      <el-form-item label="岗位编码" prop="postCode">
        <el-input v-model="form.postCode" placeholder="请输入编码名称" style="width:240px" />
      </el-form-item>
      <el-form-item label="岗位顺序" prop="postSort">
        <el-input-number v-model="form.postSort" controls-position="right" :min="0" style="width:240px" />
      </el-form-item>
      <el-form-item label="岗位状态" prop="status">
        <el-radio-group v-model="form.status">
          <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" style="width:360px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">保 存</el-button>
        <el-button @click="close()">返 回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getPost, updatePost } from '@/api/system/post';
export default {
  name: 'demo1-edit',
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 用户信息
      form: {},
      rules: {
        postName: [{ required: true, message: '岗位名称不能为空', trigger: 'blur' }],
        postCode: [{ required: true, message: '岗位编码不能为空', trigger: 'blur' }],
        postSort: [{ required: true, message: '岗位顺序不能为空', trigger: 'blur' }]
      }
    };
  },
  created() {
    const postId = this.$route.params && this.$route.params.postId;
    getPost(postId).then(response => {
      this.form = response.data;
    });
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          updatePost(this.form).then(response => {
            this.$modal.msgSuccess('修改成功');
            this.close();
          });
        }
      });
    },
    /** 关闭按钮 */
    close() {
      const obj = { path: '/system/demo/user' };
      this.$tab.closeOpenPage(obj);
    }
  }
};
</script>
<style scoped>
</style>
